/**
 * 版权所有 2009-2012山东新北洋信息技术股份有限公司
 * 保留所有权利。
 */
package com.linyaonan.leetcode.medium._16_01;

/**
 * 编写一个函数，不用临时变量，直接交换numbers = [a, b]中a与b的值。
 *
 * 示例：
 *
 * 输入: numbers = [1,2]
 * 输出: [2,1]
 * 提示：
 *
 * numbers.length == 2
 *
 *
 * @ProjectName: leetcode
 * @Package: com.linyaonan.leetcode.medium._16_01
 * @ClassName: SwapNumbersLcci
 * @Author: linyaonan
 * @Date: 2020/3/24 11:07
 */
public class SwapNumbersLcci {

    public int[] swapNumbers(int[] numbers) {
        int n0 = numbers[0];
        int n1 = numbers[1];
        n0 = n0 ^ n1;
        n1 = n0 ^ n1;
        n0 = n0 ^ n1;
        numbers[0] = n0;
        numbers[1] = n1;
        return numbers;
    }

    public int[] swapNumbers2(int[] numbers) {
        numbers[0] = numbers[0] ^ numbers[1];
        numbers[1] = numbers[0] ^ numbers[1];
        numbers[0] = numbers[0] ^ numbers[1];
        return numbers;
    }

}
